
public class GarageDoor {

	//######## Datenfelder ########
	
	public Motor myMotor = new Motor();
	private DoorState myDoorState = new Closed();
	
	//######## Konstruktoren ########
	
	
	//######## Methoden ########
	
	public void openDoor() {
		myDoorState.openDoor();
	}
	
	public void closeDoor() {
		myDoorState.closeDoor();
	}
	
	public void stopper() {
		myDoorState.stopper();
	}
	
	public Motor getMotor() {
		return myMotor;
	}
	
	public void changeState(DoorState s) {
		myDoorState = s;
	}
	
	//######## interne Klassen ########
	
	abstract class DoorState {
		abstract void closeDoor();
		abstract void openDoor();
		abstract void stopper();
	}
	
	class Open extends DoorState {
		
		public void closeDoor() {
			changeState(new Closing());
			getMotor().downwards();
		}		
		
		public void openDoor(){}
		
		public void stopper(){}
	}
	
	class Closed extends DoorState {
		public void openDoor() {
			changeState(new Opening());
			getMotor().upwards();
		}
		
		public void closeDoor(){}
		
		public void stopper(){}
	}
	
	class Opening extends DoorState {
		public void closeDoor() {
			changeState(new Closing());
			getMotor().downwards();
		}
		
		public void stopper() {
			changeState(new Open());
			getMotor().stop();
		}
		
		public void openDoor(){}
	}
	
	class Closing extends DoorState {
		public void openDoor() {
			changeState(new Opening());
			getMotor().upwards();
		}
		
		public void stopper() {
			changeState(new Closed());
			getMotor().stop();
		}
		
		public void closeDoor(){}
	}
	
	//######## interne Klassen ENDE ########
	
}
